package indi.kane.simpleproject.service.impl;

import indi.kane.simpleproject.dao.ProfessionMapper;
import indi.kane.simpleproject.entity.Profession;
import indi.kane.simpleproject.service.IProfessionService;
import indi.kane.simpleproject.util.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: ProfessionService
 * @Author: kane
 * @Date: 2019-11-05 5:36 下午
 * @Description:
 */
@Service
public class ProfessionService implements IProfessionService {
    @Resource
    private ProfessionMapper professionMapper;

    @Resource
    private RedisUtil redisUtil;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return professionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Profession record) {
        return professionMapper.insert(record);
    }

    @Override
    public int insertSelective(Profession record) {
        return professionMapper.insertSelective(record);
    }

    @Override
    public List<Profession> loadAll(){
        List<Profession> professions = (List<Profession>) redisUtil.lGetIndex("professions",-1);
        if(professions == null){
            professions = professionMapper.loadAll();
            redisUtil.lSet("professions", professions, 600);
        }
        return professions;
    }

    @Override
    public Profession selectByPrimaryKey(Integer id) {
        return professionMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Profession record) {
        return professionMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Profession record) {
        return professionMapper.updateByPrimaryKey(record);
    }
}